<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
   
</head>
<body>
    <script >
            class Base{
              constructor(){
               
              }
              isEmpty(obj){
                   if(Object.prototype.toString.call(obj)==="[object Array]"){
                      if(obj.length>0){
                          console.log(`数组有${obj.length}条`)
                      }else{
                          console.log(`空数组`)
                      }
                   }else if(Object.prototype.toString.call(obj)==="[object Object]"){
                      if(Object.keys(obj).length>0){
                        console.log(`对象有${Object.keys(obj).length}条`)
                      }else{
                        console.log('空对象')
                      }
                   }else{
                       console.log("？？？？？")
                   }
              }
              loadJs(value){
                return  new Promise((resolve,reject)=>{
                    let script=document.createElement("script");
                        script.src=value;
                        document.body.appendChild(script)
                        script.onload=function(){
                            resolve("成功了")
                        }
                })
              }
              loadCss(value){
                return new Promise((resolve,reject)=>{
                    let link=document.createElement("link");
                        // document.querySelector("head").appendChild(link);
                        link.href=value;
                        link.rel="stylesheet"
                        document.querySelector("head").appendChild(link);
                        link.onload=function(){
                            resolve("成功了")
                        }
                })
              }
              loadImg(value){
              
               return new Promise((resolve,reject)=>{
                     let img=new Image();
                     img.src=value;
                     img.onload=function(){
                         resolve(img)
                     }
                     img.onerror=function(){
                         reject("失败")
                     }
                    //  document.body.appendChild(img);
                 })
              }
              
            }
           new Base()
           class Utils extends Base{
              constructor(){
                  super()
              }
           async init(obj){
              for(var value of obj){
                     if(value.endsWith("js")){
                      await this.loadJs(value)
                     }else if(value.endsWith("css")){
                      await this.loadCss(value)
                     }else if(value.endsWith(".png")){
                      await this.loadImg(value);
                      return this.loadImg(value);
                     }
                 }
              }
           }
         let util=new Utils()
         util.isEmpty({a:1,b:2})
            util.init(["./index.js","./index.css","./1.png"]).then(res=>{
                   document.body.appendChild(res);
            })
    </script>
</body>
</html>